<template>
  <div class="x-container">
    <div class="x-main">
      <!-- 1 -->
      <div style="margin-bottom: 50px;">
        <div class="x-step_title">规划设计咨询（评审）信息</div>
        <div class="x-step_form">
          <el-form label-width="80px" :model="formData" :rules="formDataRules" ref="formData_1">
            <el-row style="width:600px">
              <el-col :span="12" class="d-flex">
                <el-form-item label="咨询时间" prop="consultTime">
                  <el-date-picker
                    type="date"
                    placeholder="请选择时间"
                    style="width:150px"
                    format="yyyy-MM-dd"
                    value-format="yyyy-MM-dd HH:mm:ss"
                    v-model="formData.consultTime"
                    :readonly="isCurrentProcess"
                  ></el-date-picker>
                </el-form-item>
              </el-col>
              <el-col :span="12" class="d-flex">
                <el-form-item label="复审时间" prop="reviewTime">
                  <el-date-picker
                    type="date"
                    placeholder="请选择时间"
                    style="width:150px"
                    format="yyyy-MM-dd"
                    value-format="yyyy-MM-dd HH:mm:ss"
                    v-model="formData.reviewTime"
                    :readonly="isCurrentProcess"
                  ></el-date-picker>
                </el-form-item>
              </el-col>
              <el-col :span="24" class="d-flex">
                <el-form-item label="咨询组长" prop="consultLeader">
                  <el-input
                    style="width:450px"
                    placeholder="请输入"
                    v-model="formData.consultLeader"
                    :readonly="isCurrentProcess"
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="24" class="d-flex">
                <el-form-item label="成员" prop="consultMember">
                  <el-input
                    style="width:450px"
                    placeholder="请输入"
                    v-model="formData.consultMember"
                    :readonly="isCurrentProcess"
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="24" class="d-flex">
                <el-form-item label="咨询与复核情况" label-width="200px" prop="consultReviewSituation">
                  <el-input
                    type="textarea"
                    :rows="6"
                    style="width:450px"
                    v-model="formData.consultReviewSituation"
                    :readonly="isCurrentProcess"
                    placeholder="请输入说明"
                  ></el-input>
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
        </div>
      </div>
      <!-- 2 -->
      <div style="margin-bottom: 50px;">
        <div class="x-step_title">规划设计咨询资料</div>
        <div class="x-step-form">
          <el-form label-width="150px" :model="formData" :rules="formDataRules" ref="formData_2">
            <el-row style="width:600px">
              <el-col :span="24">
                <el-form-item label="专家咨询意见书:" prop="expertConsultAdviceFileId">
                  <el-upload
                    :action="uploadUrl"
                    style="width:300px"
                    :on-success="handleUploadSuccess"
                    :disabled="isCurrentProcess"
                    accept=".pdf"
                    v-if="!isCurrentProcess"
                  >
                    <el-button type="primary" size="small">点击上传</el-button>
                  </el-upload>
                  <div class="viewDocment" v-if="isCurrentProcess">
                    <seeFujian
                      v-if="formData.expertConsultAdviceFile"
                      @openPdf="seePdf"
                      :file-name="formData.expertConsultAdviceFile | backFileName"
                      :file-url="formData.expertConsultAdviceFile.filePath"
                    />
                    <!-- <span><i class="el-icon-document"/>{{formData.expertConsultAdviceFile | backFileName}}</span>
                    <a style="color: rgb(64, 158, 255);margin-left:5px" @click="seePdf(formData.expertConsultAdviceFile.filePath,formData.expertConsultAdviceFile.fileName)">查看</a>-->
                  </div>
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
        </div>
      </div>
      <!-- 3 -->
      <div style="padding-left: 80px;">
        <el-button type="primary" @click="handleSubmit" v-if="!isCurrentProcess">提交</el-button>
        <el-button @click="$router.push('/projectManagement/planningStage/dealwith')">返回</el-button>
      </div>
    </div>
    <el-dialog :close-on-click-modal="false" :title="pdfName" :visible.sync="pdfFlag" width="50%">
      <div class="pdfBox">
        <iframe :src="$https + pdfUrl" style="width:100%;height:600px;" frameborder="0"></iframe>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import config from "@/config/index.js";
import { submitData, getDetail } from "@/api/plannDesignBudget/consulting.js";
import {
  validateNotNull,
  validateUpload,
  validateDatetime
} from "@/utils/validate.js";
import seeFujian from "@/components/seeFujian";
export default {
  components: {
    seeFujian
  },
  data() {
    return {
      pdfUrl: "",
      pdfFlag: false,
      pdfName: "",
      baseUrl: config.baseUrl,
      projectId: localStorage.getItem("projectId") * 1,
      formData: {
        projectId: localStorage.getItem("projectId") * 1,
        consultTime: "",
        reviewTime: "",
        consultLeader: "",
        consultMember: "",
        consultReviewSituation: "",
        expertConsultAdviceFileId: ""
      },
      formDataRules: {
        consultTime: [{ validator: validateDatetime, trigger: "change" }],
        reviewTime: [{ validator: validateDatetime, trigger: "change" }],
        consultLeader: [{ validator: validateNotNull, trigger: "blur" }],
        consultMember: [{ validator: validateNotNull, trigger: "blur" }],
        consultReviewSituation: [
          { validator: validateNotNull, trigger: "blur" }
        ],
        expertConsultAdviceFileId: [
          { validator: validateUpload, trigger: "blur" }
        ]
      },
      uploadUrl: config.uploadUrl
    };
  },
  computed: {
    isCurrentProcess: function() {
      let isTrue =
        localStorage.getItem("key") ==
        "PLANNING_DESIGN_AND_BUDGETING_CITY_CENTER_REVIEW";
      if (localStorage.getItem("lookStatus") == 2) {
        isTrue = false;
      }
      return !isTrue;
    }
  },
  filters: {
    backFileName: function(data) {
      if (data) {
        return data.fileName;
      } else {
        return "";
      }
    },
    backFilePath: function(data, baseUrl) {
      if (data) {
        return baseUrl + data.filePath;
      } else {
        return "";
      }
    }
  },
  created() {
    this.getDetail();
  },
  methods: {
    //查看当前PDF
    seePdf(url, name) {
      this.pdfFlag = true;
      this.pdfUrl = url;
      this.pdfName = name;
    },
    handleUploadSuccess: function(res, file, fileList) {
      //文件上传成功回调
      this.formData.expertConsultAdviceFileId = res.data.id;
      this.$refs["formData_2"].validate();
    },
    handleSubmit: function() {
      //数据提交
      let isTrue1 = false,
        isTrue2 = false;
      this.$refs["formData_1"].validate(valid => {
        isTrue1 = Boolean(valid);
      });
      this.$refs["formData_2"].validate(valid => {
        isTrue2 = Boolean(valid);
      });
      if (isTrue1 && isTrue2) {
        const loading = this.$loading({
          lock: true,
          text: "Loading",
          spinner: "el-icon-loading",
          background: "rgba(0, 0, 0, 0.7)"
        });
        submitData(this.formData)
          .then(res => {
            loading.close();
            this.$message({
              message: "提交成功！",
              type: "success"
            });
            this.$router.push("/projectManagement/planningStage/dealwith");
          })
          .catch(res => {
            loading.close();
          });
      }
    },
    getDetail() {
      //获取页面数据
      const loading = this.$loading({
        lock: true,
        text: "Loading",
        spinner: "el-icon-loading",
        background: "rgba(0, 0, 0, 0.7)"
      });
      getDetail({ projectId: this.projectId })
        .then(res => {
          loading.close();
          if (res.data) {
            this.formData = res.data;
          }
        })
        .catch(res => {
          loading.close();
        });
    }
  }
};
</script>

<style scoped lang="scss">
.x-container {
  width: 100%;
  min-height: calc(100vh - 114px);
  padding: 20px;
  background: rgba(247, 248, 250, 1);
  .x-main {
    padding: 20px;
    background-color: #fff;
    .x-step_title {
      font-size: 18px;
      font-family: PingFang SC;
      font-weight: bold;
      line-height: 25px;
      color: rgba(77, 77, 77, 1);
      margin-bottom: 30px;
    }
  }
}
.d-flex {
  display: flex;
  justify-content: flex-end;
}
</style>
